<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>资源类别管理_资源共享平台</title>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
</head>
<body>
<div style="padding: 20px;">
    <span class="layui-breadcrumb">
        <a>首页</a>
        <a><cite>资源类别管理</cite></a>
    </span>
    <div style="padding-top: 20px;">
        <table id="resTypeListTable" lay-filter="resTypeListTable"></table>
    </div>
</div>

<script type="text/html" id="toolbarTpl">
    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
</script>
<script type="text/html" id="toolTpl">
    <button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</button>
    <button class="layui-btn layui-btn-xs layui-btn-warm" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</button>
</script>

<script src="/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    let $, layer, table;
    layui.use(['layer', 'table'], function () {
        $ = layui.jquery,
            layer = layui.layer,
            table = layui.table;

        table.render({
            elem: '#resTypeListTable',
            toolbar: '#toolbarTpl',
            url: '/admin/resType/list',
            headers: {'Cache-Control':'no-cache'},
            cols: [[
                {type: 'checkbox'},
                {field: 'name', width: 150, title: '资源类别'},
                {field: 'description', title: '类别描述'},
                {field: 'sort', width: 100, title: '排列序号', align: 'center'},
                {field: 'action', width: 150, title: '操作', align: 'center', templet: '#toolTpl'}
            ]],
            page: true
        });

        // 触发工具栏事件
        table.on('toolbar(resTypeListTable)', function (obj) {
            switch (obj.event) {
                case 'add': // 发布资源
                    add();
                    break;
            }
        });

        // 触发单元格工具事件
        table.on('tool(resTypeListTable)', function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case 'edit': // 编辑
                    edit(data.id);
                    break;
                case 'delete': // 删除
                    deleteOne(data.id);
                    break;
            }
        });
    });

    function add() {
        layer.open({
            type: 2,
            title: '添加资源类别',
            area: ['500px', '400px'],
            content: '/admin/resType/edit'
        });
    }

    function edit(id) {
        layer.open({
            type: 2,
            title: '修改资源类别',
            area: ['500px', '400px'],
            content: '/admin/resType/edit/' + id
        });
    }

    function deleteOne(id) {
        layer.confirm('您确定要删除这条记录吗？', {
            title: "系统提示",
            btn: ['确定', '取消']
        }, function () {
            layer.closeAll('dialog');
            $.post("/admin/resType/delete", {"id": id}, function (result) {
                if (result.success) {
                    layer.msg("删除成功！");
                    table.reload("resTypeListTable", {});
                } else {
                    layer.msg("删除失败，请联系管理员！");
                }
            }, "json");
        }, function () {

        });
    }
    /*]]>*/
</script>
</body>
</html>